package com.zhang.activity;

import java.util.ArrayList;

import com.zhang.little_sample.R;
import com.zhang.little_sample.R.drawable;

import android.app.Dialog;
import android.app.ActionBar.LayoutParams;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.ViewGroup.MarginLayoutParams;
import android.widget.TextView;

public class DiyDialog extends Dialog {

	public interface OnDiyDialogListener {
		// 定义回调事件
		public void back(String name);
	}

	private Context context;
	private String name;
	private ArrayList<String> arrayListProvince;// 省
	private ArrayList<String> arrayListCity;// 城
	private ArrayList<String> arrayListArea;// 区
	private ArrayList<String> arrayListStreet;// 街道
	private OnDiyDialogListener onDiyDialogListener;
	private XCFlowLayout mFlowLayout;
	private String testNames[] = { "welcome", "android", "TextView", "apple",
			"jamy", "kobe bryant", "jordan", "layout", "viewgroup", "margin",
			"padding", "text", "name", "type", "search", "logcat" };

	public DiyDialog(Context context, String name,
			OnDiyDialogListener onDiyDialogListener) {
		super(context);
		this.context = context;
		this.name = name;
		this.onDiyDialogListener = onDiyDialogListener;
	}

	// 创建Dialog
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.diydialog);
		initData();
		initChildViews();
	}

	// 加载子控件
	private void initChildViews() {
		mFlowLayout = (XCFlowLayout) findViewById(R.id.flowlayout);
		MarginLayoutParams lp = new MarginLayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		lp.leftMargin = 5;
		lp.rightMargin = 5;
		lp.topMargin = 5;
		lp.bottomMargin = 5;
		for (int i = 0; i < testNames.length; i++) {
			final TextView view = new TextView(context);
			view.setText(testNames[i]);
			view.setTextColor(Color.BLACK);
			view.setTextSize(20);
		//  view.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.bg_edittext));
			view.setBackgroundResource(R.drawable.bg_edittext);
			view.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					onDiyDialogListener.back(view.getText().toString());
					DiyDialog.this.dismiss();
				}
			});
			mFlowLayout.addView(view, lp);
		}
	}

	private void initData() {

	}

}
